// pages/mine/mine.js
import config from '../../utils/config';
const { operateGetDeal, operateGetUnDeal } = require("../../utils/api");
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myTitle: "长兴诺力售后管理系统",
    userInfo: null,
    waitmassageNumber: 0,
    repliedMessageNumber: 0,
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
    });
    this.operateGetDeal();
    this.operateGetUnDeal();
  },
  goMine() {
    wx.navigateTo({
      url: '/pages/editMine/editMine',
    })
  },
  goShop(){
    wx.redirectTo({
      url: '/pages/pointsShop/pointsShop',
    })
  },
  goWaitMsg() {
    wx.navigateTo({
      url: '/pages/waitmassage/waitmassage',
    })
  },
  goRepliedMsg() {
    wx.navigateTo({
      url: '/pages/repliedMessage/repliedMessage',
    })
  },
  goPoints() {
    wx.navigateTo({
      url: '/pages/points/points',
    })
  },

  operateGetDeal() {
    const data = { PhoneNumber: this.data.userInfo.PhoneNumber, };
    operateGetDeal(data).then(res => {
      if(res.code === 4002140) {
        this.setData({
          repliedMessageNumber : res.data.length,
        });
      }
    })
  },

  operateGetUnDeal: function (){
    const data = { PhoneNumber: this.data.userInfo.PhoneNumber, };
    operateGetUnDeal(data).then(res => { 
      if (res.code) {
        this.setData({
          waitmassageNumber : res.data.length,
        });
      }
    });
  },

  getUserAvatar: function() {
    const that = this;

    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log('用户信息:', res.userInfo);
        const avatarUrl = res.userInfo.avatarUrl; // 获取用户头像URL
        that.setData({
          userAvatar: avatarUrl,
          userName: res.userInfo.nickName // 如果你也想获取用户名
        });
      },
      fail: (err) => {
        console.error('获取用户信息失败:', err);
        wx.showToast({
          title: '获取头像失败',
          icon: 'none'
        });
      }
    });
  },
})